<?php

require_once 'include/common.inc.php';
$view->assign('pagetitle', "用户登录");
$view->assign('keywords', "User,Login,登录,ISUX,ISUX Examiner");
$view->assign('description', "ISUX招聘笔试题目管理系统");
$view->assign('pagestyle', array('user'));
$view->assign('pagescript', array('user'));
empty($action) && $action = "login"; 
switch ($action) {
    case 'register':
        register();
        break;
    case 'login':
        login();
        break;
    case 'doregister':
        doregister();
        break;
    case 'dologin':
        dologin();
        break;
    default:
        logout();
}

function register(){

}

function doregister(){

}

function login() {
	global $view;
    $view->display('login.html');
}

function dologin() {
	$account = $pass = '';
	array_key_exists('username', $_POST) && $account = trim($_POST['username']);
	array_key_exists('password', $_POST) && $pass = trim($_POST['password']);
	$result = array('success' => false, 'message' => '');
	if ($account && $pass) {
		require_once INCLUDES . 'user.class.php';
		$chklogin = User::UserLogin($account, $pass);
		if ($chklogin['logined']) {
			@session_start();
			$_SESSION['user'] = $chklogin['user'];
		}
		$result['success'] = $chklogin['logined'];
		$result['message'] = $chklogin['message'];
	} else {
		$result['message'] = '用户名和密码均不能为空!';
	}
	header('content-type:text/javascript;charset=utf-8');
	echo json_encode($result);
}

function dologout() {

}

function logout() {}